<div class="common-tit">
  <h2>添加课程</h2>
  <span>课程系统 > 课程列表 > 修改课程</span>
</div>
<div class="cur-box">
  <h3>
    <em>*</em>
    <span>基本信息</span>
  </h3>
  <div class="cur-basic">
    <ul class="cb-box clearfix">
      <li class="bas-list">
        <input type="text" name="" readOnly="readOnly" value="<%= @course_info.sale_type %>">
      </li>
      <li class="bas-list">
        <input type="text" name="" readOnly="readOnly" value="<%= @course_info.sale_type %>">
      </li>
      <li class="bas-list">
        <input type="text" class="ba-cur required" placeholder="课程名称" value="<%= @course_info.name %>">
      </li>
      <li class="bas-list">
        <div class="list-box spe clearfix" choice="selected">
          <div class="downbtn">
            <span data_id="<%= @course_info.teacher.id %>"><%= @course_info.teacher.name %></span>
            <em></em>
          </div>
          <ul class="dropdown-menu">
            <li class="cho-tit">导师</li>
            <% @teachers.each do |teacher| %>
              <li data_id="<%= teacher.id %>"><%= "#{teacher.name}" %></li>
            <%end%>
          </ul>
        </div>
        <b>请选择</b>
      </li>
      <li class="bas-list">
        <div class="list-box spe clearfix" choice="selected">
          <div class="downbtn">
            <span data_id="<%= @course_info.room.id %>"><%= @course_info.room.room_name %></span>
            <em></em>
          </div>
          <ul class="dropdown-menu">
            <li class="cho-tit">教室</li>
            <% @rooms.each do |room| %>
              <li data_id="<%= room.id %>"><%= "#{room.room_name}" %></li>
            <%end%>
          </ul>
        </div>
        <b>请选择</b>
      </li>
      <li class="bas-list">
        <div class="list-box spe clearfix" choice="selected">
          <div class="downbtn">
            <span data_id="<%= @course_info.dance_type %>"><%= @course_info.dance_type %></span>
            <em></em>
          </div>
          <ul class="dropdown-menu">
            <li class="cho-tit">舞种</li>
            <% Company::DANCE_TYPE.each do |key, value| %>
              <li data_id="<%= key %>"><%= value %></li>
            <%end%>
          </ul>
        </div>
        <b>请选择</b>
      </li>
      <li class="bas-list">
        <div class="list-box spe clearfix" choice="selected">
          <div class="downbtn">
            <span data_id="<%= @course_info.age_group %>"><%= @course_info.age_group %></span>
            <em></em>
          </div>
          <ul class="dropdown-menu">
            <li class="cho-tit">授课对象</li>
            <% Company::AGE_GROUP.each do |key, value| %>
              <li data_id="<%= key %>"><%= value %></li>
            <%end%>
          </ul>
        </div>
        <b>请选择</b>
      </li>
      <li class="bas-list">
        <input type="text" class="ba-cur required" placeholder="课程时长" value="<%= @course_info.duration %>" onkeyup="intNum(this)">
        <span class="bas-m">分钟</span>
      </li>
    </ul>
  </div>
  <%= tag(:input, :type => 'hidden', :name => 'utf-8',:value => "✓") %>
  <%= tag(:input, :type => "hidden", :name =>  request_forgery_protection_token.to_s, :value =>   form_authenticity_token) %> 
  <div class="update_preserve">保存</div>
</div>

<script src="/assets/js/common.js"></script>
<script type="text/javascript">
  // 添加课程模块 保存按钮
$(".update_preserve").on("click", function() { 
  if (confirmSet()) {
    console.log("可以跳转到下一步");
    var isOrde;
    if($(".cb-box .list-box").eq(1).find("span").text() == "私教") {
      isOrder = true;
    } else {
      if ($(".order .check").prev("input").attr("checked")) {
        isOrder = true;
      } else {
        isOrder = false;
      }
    };
    
    var postJson = {
        "courseinfo" : [{
            "teacher_id" : $(".cb-box .list-box").eq(0).find("span").attr("data_id"),
            "room_id" : $(".cb-box .list-box").eq(1).find("span").attr("data_id"),
            "dance_type" : $(".cb-box .list-box").eq(2).find("span").text(),
            "age_group" : $(".cb-box .list-box").eq(3).find("span").text(),
            "name" : $(".cb-box input").eq(2).val(),
            "duration" : $(".cb-box input").eq(3).val(),          
      }],
            'course_info_id': "<%= @course_info.id %>",
            'utf-8': $("input[name=utf-8]").val(),
            'authenticity_token': $("input[name=authenticity_token]").val()
    };    
    console.log(postJson);    
    $.ajax({
      data: postJson,
      type:'post', url:"/admin/course_infos/update_course",
      success: function(data) {
        if (data.error) {
          // console.log("wrong");
        } 
      }
    });
  }
})
</script>
